home *** CD-ROM | disk | FTP | other *** search
- Path: maple.sover.net!mountain
- From: mountain@maple.sover.net (Steve Mount)
- Newsgroups: comp.lang.c
- Subject: Re: Converting Strings to Upper Case
- Date: 19 Mar 1996 16:44:19 GMT
- Organization: SoVerNet, Inc.
- Message-ID: <4imo93$mu@thrush.sover.net>
- References: <4ifra6$52i@scipio.cyberstore.ca> <4ih7l3$526@thrush.sover.net> <314D8C90.55C6@oak.westol.com>
- NNTP-Posting-Host: maple.sover.net
- X-Newsreader: TIN [version 1.2 PL2]
-
- Mark Kintigh (breetai@oak.westol.com) wrote:
- : Steve Mount wrote:
- : >
- : > In article <4ifra6$52i@scipio.cyberstore.ca>, ejw@news.cyberstore.ca says...
- : > >I need to write a function to convert a string containg upper or lower case
- : > >characters to the opposite case. Something like::
- : > void strnlwr(char *buffer, int len)
- : > {
- : > register int i;
- : > for (i=0;i<len;i++) buffer[i] = tolower(buffer[i]);
- : > return;
- : > }
- : >
- : > Note I added a length checker, as this was required; it may not be the most
- : > efficient, but it gets the job done. It also prevents me from duplicating
- : > the code that tolower/toupper does.
-
- : You don't need the length. You could just use....
-
- : void str2upper(char *str)
- : {
- : while(*str!='\0')
- : {
- : *str = toupper(*str);
- : str++;
- : }
- : }
-
- : Of course, this assumes that you have properly terminated the string. :)
-
- Much of our data is similar to this:
- struct {
- char firstname[12];
- char lastname[12];
- ...etc...
- };
- with no null-termination. So almost all of our in-house functions take
- a length. The function I posted follows this "standard" of ours. If
- you can guarantee null-temrination, then it is a lot simpler, and
- probably quicker, as your function shows. But we can't guarantee
- null-termination. In fact, most of the time we can guarantee
- non-null-termination!
-
- +============================================================================+
- | Steve Mount, Software Engineer Work: sjjm@hawkeye.idx.com |
- | CIS: 73720,3404 MSN: S_Mountain Home: mountain@sover.net |
- | AOL: Mountain |
- | WWW: http://www.sover.net/~mountain/ "Fight, Win, Prevail!" |
- +============================================================================+
-